home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / More Files / form-to-email_compmaintenance.php < prev    next >
PHP Script  |  2013-07-17  |  2KB  |  79 lines

  1. <?php
  2.  
  3. if(!isset($_POST['submit']))
  4. {
  5.     //This page should not be accessed directly. Need to submit the form.
  6.     echo "error; you need to submit the form!";
  7. }
  8.  
  9. $copy_email = $_POST['CopyEmail'];
  10. $school = $_POST['School'];
  11. $room_number = $_POST['LocationRoom'];
  12. $requested = $_POST['Requested'];
  13. $problem = $_POST['Problem'];
  14. $contact = $_POST['Contact'];
  15. $date = date("F j, Y, g:i a");
  16.  
  17. //Validate first
  18. if(empty($contact)||empty($copy_email)) 
  19. {
  20.     echo "Name and email are mandatory!";
  21.     exit;
  22. }
  23.  
  24. if(IsInjected($copy_email))
  25. {
  26.     echo "Bad email value!";
  27.     exit;
  28. }
  29.  
  30. $email_subject = "Maintenance Work Order - $school";
  31. $email_body = "The following work order was entered on $date \r\n
  32.     SCHOOL: $school 
  33.     LOCATION-ROOM: $room_number 
  34.     REQUESTED: $requested 
  35.     CONTACT: $contact 
  36.     PROBLEM: $problem \r\n";
  37.     
  38. $email_to = "psines@access.k12.wv.us,rmarshal@access.k12.wv.us,mlmurray@access.k12.wv.us";
  39. $headers = "From: $copy_email\r\n";
  40. $headers .= "CC: $copy_email\r\n";
  41.  
  42.  
  43. //Send the email!
  44. if (mail($email_to,$email_subject,$email_body,$headers)){
  45.  
  46.  
  47. //done. redirect to thank-you page.
  48. header('Location: thank-youworkmaintenance.html');
  49. }
  50. else{
  51. header('Location: problem.html');
  52. }
  53.  
  54.  
  55. // Function to validate against any email injection attempts
  56. function IsInjected($str)
  57. {
  58.   $injections = array('(\n+)',
  59.               '(\r+)',
  60.               '(\t+)',
  61.               '(%0A+)',
  62.               '(%0D+)',
  63.               '(%08+)',
  64.               '(%09+)'
  65.               );
  66.   $inject = join('|', $injections);
  67.   $inject = "/$inject/i";
  68.   if(preg_match($inject,$str))
  69.     {
  70.     return true;
  71.   }
  72.   else
  73.     {
  74.     return false;
  75.   }
  76. }
  77.  
  78.  
  79. ?>